# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=sslh
pkgver=2.1.2
pkgrel=0
pkgdesc="Applicative Protocol Multiplexer (e.g. share SSH and HTTPS on the same port)"
url="https://www.rutschle.net/tech/sslh/README.html"
arch="all"
license="GPL-2.0-or-later"
makedepends="libconfig-dev libcap-dev pcre2-dev libev-dev perl
autoconf automake libtool"
checkdepends="perl-conf-libconfig perl-io-socket-inet6 lcov valgrind"
subpackages="$pkgname-fail2ban::noarch $pkgname-doc $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/yrutschle/sslh/archive/refs/tags/v$pkgver.tar.gz
	fix-make-install.patch
	fail2ban.patch
	config.patch
	$pkgname.initd
	$pkgname.confd
	"
# FIXME: Some tests fail.
# Can't test in chroot due to sockets and processes opened. (?)
options="!check"

prepare() {
	default_prepare
	aclocal && autoconf
	libtoolize
}

build() {
	./configure --prefix=/usr
	make
}

check() {
	make test
}

package() {
	make DESTDIR="$pkgdir" PREFIX=/usr install

	install -D -m644 basic.cfg "$pkgdir/etc/$pkgname.conf"
	install -D -m755 "$srcdir/$pkgname.initd" "$pkgdir/etc/init.d/$pkgname"
	install -D -m644 "$srcdir/$pkgname.confd" "$pkgdir/etc/conf.d/$pkgname"
}

fail2ban() {
	install_if="$pkgname=$pkgver-r$pkgrel fail2ban"

	cd "$builddir"

	install -D -m644 scripts/fail2ban/sslh-ssh.conf \
		"$subpkgdir"/etc/fail2ban/filter.d/sslh-ssh.conf

	install -D -m644 scripts/fail2ban/jail.conf \
		"$subpkgdir"/etc/fail2ban/jail.d/sslh-ssh.conf
}

doc() {
	default_doc

	cd "$builddir"
	install -Dm 644 basic.cfg "$subpkgdir/usr/share/doc/$pkgname/basic.cfg"
	install -Dm 644 example.cfg "$subpkgdir/usr/share/doc/$pkgname/example.cfg"
}

sha512sums="
4f0b3c61e6153b912b11c49baba2df1a9df6732ea9fcdee628bf02043efc1b6505ac97eec97740c67d09f7d58a1bb79e0e06d949cb7fabcffa1fb91733372631  sslh-2.1.2.tar.gz
a5676b7b4626f298c6d31ba5bbd27a1b1732de04f9b54b55d421a80ff12f7ca15aae5c9aef36af23db4ba0efa4c2c3761fb17ace715f7df0baeac34a9ec859c4  fix-make-install.patch
5773ee1d91e099726b614dbe385f2668699d25029fc300b664411c6082e95d3f27df11b9b1489bee3444c81bf941b8db13b4d382343788e47408c593c4531816  fail2ban.patch
87779a2a2bacf560146184bf64a6fdb49930fe97acf3770ad2e153dbbf9317110dc37fc7851df58f035866ca06983adc00251f871eaa6bfd8cc56c5292d437fa  config.patch
20ad403c7e8bd37c849263886ff4307a478fbeaec74d52b7db864dea2e9bdafb2c501afd70fa2621385baf3536553a79cee006b4a629260921d2e08db7991696  sslh.initd
7eaf99c6fb4505d0562c46ed2b3ae656b7c7c96223f2c7f11ab1bed72e9df0223a7ef02277ac50a633d165238efb8c54044eff38b488a7884b6671120d9e3f3e  sslh.confd
"
